﻿using System;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;

namespace SAFPodcast.WP8.DTO.Entities
{
    [Table]
    public class Feed : INotifyPropertyChanged, INotifyPropertyChanging
    {
        #region Id
        private int id;
        [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
        public int Id
        {
            get
            {
                return id;
            }
            set
            {
                if (id != value)
                {
                    NotifyPropertyChanging("Id");
                    id = value;
                    NotifyPropertyChanged("Id");
                }
            }
        }
        #endregion
        #region URI
        private String uri;
        [Column]
        public String URI
        {
            get
            {
                return uri;
            }
            set
            {
                if (uri != value)
                {
                    NotifyPropertyChanging("URI");
                    uri = value;
                    NotifyPropertyChanged("URI");
                }
            }
        }
        #endregion
        #region ImagePath
        private String imagePath;
        [Column(CanBeNull=true)]
        public String ImagePath
        {
            get
            {
                return imagePath;
            }
            set
            {
                if (imagePath != value)
                {
                    NotifyPropertyChanging("ImagePath");
                    imagePath = value;
                    NotifyPropertyChanged("ImagePath");
                }
            }
        }
        #endregion
        #region LastUpdate
        private DateTime lastUpdate;
        [Column]
        public DateTime LastUpdate
        {
            get
            {
                return lastUpdate;
            }
            set
            {
                if (lastUpdate != value)
                {
                    NotifyPropertyChanging("LastUpdate");
                    lastUpdate = value;
                    NotifyPropertyChanged("LastUpdate");
                }
            }
        }
        #endregion
        #region Name
        private String name;
        [Column]
        public String Name
        {
            get
            {
                return name;
            }
            set
            {
                if (name != value)
                {
                    NotifyPropertyChanging("Name");
                    name = value;
                    NotifyPropertyChanged("Name");
                }
            }
        }
        #endregion
        #region Version
        [Column(IsVersion = true)]
        protected Binary _version;
        #endregion
        #region Equals / GetHashCode
        public override bool Equals(object obj)
        {
            var result = false;
            var that = obj as Feed;
            if (that != null)
            {
                result = that.Id == this.Id;
            }

            return result;
        }

        public override int GetHashCode()
        {
            return Id.GetHashCode();
        }
        #endregion
        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
        #region INotifyPropertyChanging Members
        public event PropertyChangingEventHandler PropertyChanging;
        private void NotifyPropertyChanging(string propertyName)
        {
            if (PropertyChanging != null)
            {
                PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
            }
        }
        #endregion
    }
}
